home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / shadez.swf / scripts / Local / Game / World / CAngle.as next >
Encoding:
Text File  |  2011-08-19  |  14.3 KB  |  523 lines

  1. package Local.Game.World
  2. {
  3.    import flash.geom.Matrix;
  4.    
  5.    public class CAngle
  6.    {
  7.       
  8.       public static const mDirectionIndexes:Object = {
  9.          "E":0,
  10.          "SE":1,
  11.          "S":2,
  12.          "SW":3,
  13.          "W":4,
  14.          "NW":5,
  15.          "N":6,
  16.          "NE":7
  17.       };
  18.       
  19.       public static const bNE:int = 128;
  20.       
  21.       public static const SEARCHES4:Object = {
  22.          "E":["E","N","S","W"],
  23.          "S":["S","W","E","N"],
  24.          "W":["W","S","N","E"],
  25.          "N":["N","E","W","S"]
  26.       };
  27.       
  28.       public static const bE:int = 1;
  29.       
  30.       public static const mEast:Object = {
  31.          "mDirection":0,
  32.          "mName":"E",
  33.          "mNeighbour":"nEast",
  34.          "mBits":bE,
  35.          "mDelta":new CPosition(1,0),
  36.          "mSubDelta":new CPosition(1 / 2,0)
  37.       };
  38.       
  39.       public static const bNW:int = 32;
  40.       
  41.       public static const mDirectionNeighbours:Array = ["nEast","nSouthEast","nSouth","nSouthWest","nWest","nNorthWest","nNorth","nNorthEast"];
  42.       
  43.       public static const bS:int = 4;
  44.       
  45.       public static const mDirections4:Array = ["E","S","W","N"];
  46.       
  47.       public static const bSE:int = 2;
  48.       
  49.       public static const mNorthEast:Object = {
  50.          "mDirection":7,
  51.          "mName":"NE",
  52.          "mNeighbour":"nNorthEast",
  53.          "mBits":bNE,
  54.          "mDelta":new CPosition(1,-1),
  55.          "mSubDelta":new CPosition(1 / 2,-1 / 2)
  56.       };
  57.       
  58.       public static const mDirections8:Array = ["E","SE","S","SW","W","NW","N","NE"];
  59.       
  60.       private static const negDirStack:Array = [0,-1,1,-2,2,-3,3,4];
  61.       
  62.       public static const bS_E:int = bE | bS;
  63.       
  64.       private static const MAXMASK:Number = 4294967295;
  65.       
  66.       private static const CONVRAD:Number = ┬º┬ºpop();
  67.       
  68.       private static const CONVRADM:Number = 1 / CONVRAD;
  69.       
  70.       public static const bSW:int = 8;
  71.       
  72.       public static const mSouthWest:Object = {
  73.          "mDirection":3,
  74.          "mName":"SW",
  75.          "mNeighbour":"nSouthWest",
  76.          "mBits":bSW,
  77.          "mDelta":new CPosition(-1,1),
  78.          "mSubDelta":new CPosition(-1 / 2,1 / 2)
  79.       };
  80.       
  81.       public static const bW:int = 16;
  82.       
  83.       public static const mWest:Object = {
  84.          "mDirection":4,
  85.          "mName":"W",
  86.          "mNeighbour":"nWest",
  87.          "mBits":bW,
  88.          "mDelta":new CPosition(-1,0),
  89.          "mSubDelta":new CPosition(-1 / 2,0)
  90.       };
  91.       
  92.       public static const bN:int = 64;
  93.       
  94.       public static const bN_W:int = bW | bN;
  95.       
  96.       public static const mNorth:Object = {
  97.          "mDirection":6,
  98.          "mName":"N",
  99.          "mNeighbour":"nNorth",
  100.          "mBits":bN,
  101.          "mDelta":new CPosition(0,-1),
  102.          "mSubDelta":new CPosition(0,-1 / 2)
  103.       };
  104.       
  105.       public static const mDirectionNames:Array = ["E","SE","S","SW","W","NW","N","NE"];
  106.       
  107.       public static const mSouth:Object = {
  108.          "mDirection":2,
  109.          "mName":"S",
  110.          "mNeighbour":"nSouth",
  111.          "mBits":bS,
  112.          "mDelta":new CPosition(0,1),
  113.          "mSubDelta":new CPosition(0,1 / 2)
  114.       };
  115.       
  116.       public static const bS_W:int = bW | bS;
  117.       
  118.       public static const mNorthWest:Object = {
  119.          "mDirection":5,
  120.          "mName":"NW",
  121.          "mNeighbour":"nNorthWest",
  122.          "mBits":bNW,
  123.          "mDelta":new CPosition(-1,-1),
  124.          "mSubDelta":new CPosition(-1 / 2,-1 / 2)
  125.       };
  126.       
  127.       public static const mDirectionNameToNeighbour:Object = {
  128.          "E":"nEast",
  129.          "SE":"nSouthEast",
  130.          "S":"nSouth",
  131.          "SW":"nSouthWest",
  132.          "W":"nWest",
  133.          "NW":"nNorthWest",
  134.          "N":"nNorth",
  135.          "NE":"nNorthEast"
  136.       };
  137.       
  138.       public static const bN_E:int = ┬º┬ºpop();
  139.       
  140.       private static const posDirStack:Array = [0,1,-1,2,-2,3,-3,4];
  141.       
  142.       public static const bESNW:int = ┬º┬ºpop() | ┬º┬ºpop();
  143.       
  144.       public static const mSouthEast:Object = {
  145.          "mDirection":1,
  146.          "mName":"SE",
  147.          "mNeighbour":"nSouthEast",
  148.          "mBits":bSE,
  149.          "mDelta":new CPosition(1,1),
  150.          "mSubDelta":new CPosition(1 / 2,1 / 2)
  151.       };
  152.       
  153.       public static const mSearchRH:Object = {
  154.          "E":[mEast,mSouthEast,mNorthEast,mSouth,mNorth,mSouthWest,mNorthWest,mWest],
  155.          "SE":[mSouthEast,mSouth,mEast,mNorthEast,mSouthWest,mNorth,mWest,mNorthWest],
  156.          "S":[mSouth,mSouthEast,mSouthWest,mEast,mWest,mNorthEast,mNorthWest,mNorth],
  157.          "SW":[mSouthWest,mSouth,mWest,mSouthEast,mNorthWest,mNorth,mEast,mNorthEast],
  158.          "W":[mWest,mNorthWest,mSouthWest,mNorth,mSouth,mSouthEast,mNorthEast,mEast],
  159.          "NW":[mNorthWest,mNorth,mWest,mNorthEast,mSouthWest,mEast,mSouth,mSouthEast],
  160.          "N":[mNorth,mNorthWest,mNorthEast,mWest,mEast,mSouthWest,mSouthEast,mSouth],
  161.          "NE":[mNorthEast,mEast,mNorth,mSouthEast,mNorthWest,mSouth,mWest,mSouthWest]
  162.       };
  163.       
  164.       public static const mDirectionByName:Object = {
  165.          "E":mEast,
  166.          "SE":mSouthEast,
  167.          "S":mSouth,
  168.          "SW":mSouthWest,
  169.          "W":mWest,
  170.          "NW":mNorthWest,
  171.          "N":mNorth,
  172.          "NE":mNorthEast
  173.       };
  174.       
  175.       public static const mSearchLH:Object = {
  176.          "E":[mEast,mNorthEast,mSouthEast,mNorth,mSouth,mNorthWest,mSouthWest,mWest],
  177.          "SE":[mSouthEast,mEast,mSouth,mSouthWest,mNorthEast,mWest,mNorth,mNorthWest],
  178.          "S":[mSouth,mSouthWest,mSouthEast,mWest,mEast,mNorthWest,mNorthEast,mNorth],
  179.          "SW":[mSouthWest,mWest,mSouth,mNorthWest,mSouthEast,mEast,mNorth,mNorthEast],
  180.          "W":[mWest,mSouthWest,mNorthWest,mSouth,mNorth,mNorthEast,mSouthEast,mEast],
  181.          "NW":[mNorthWest,mWest,mNorth,mSouthWest,mNorthEast,mSouth,mEast,mSouthEast],
  182.          "N":[mNorth,mNorthEast,mNorthWest,mEast,mWest,mSouthEast,mSouthWest,mSouth],
  183.          "NE":[mNorthEast,mNorth,mEast,mNorthWest,mSouthEast,mWest,mSouth,mSouthWest]
  184.       };
  185.       
  186.       public static const SEARCHES:Object = mSearchLH;
  187.       
  188.       public static const mDirectionByNeighbour:Object = {
  189.          "nEast":mEast,
  190.          "nSouthEast":mSouthEast,
  191.          "nSouth":mSouth,
  192.          "nSouthWest":mSouthWest,
  193.          "nWest":mWest,
  194.          "nNorthWest":mNorthWest,
  195.          "nNorth":mNorth,
  196.          "nNorthEast":mNorthEast
  197.       };
  198.       
  199.       public static const mDirectionByIndex:Array = [mEast,mSouthEast,mSouth,mSouthWest,mWest,mNorthWest,mNorth,mNorthEast];
  200.       
  201.       private static const MAXANGLE:Number = ┬º┬ºpop();
  202.       
  203.       private static const CONVDEG:Number = MAXANGLE / 360;
  204.       
  205.       private static const CONVDEGM:Number = 1 / CONVDEG;
  206.       
  207.       {
  208.          ┬º┬ºpush(┬º┬ºfindproperty(bESNW));
  209.          ┬º┬ºpush(bE);
  210.          ┬º┬ºpush(bS);
  211.          if(true)
  212.          {
  213.             ┬º┬ºpush(┬º┬ºpop() | ┬º┬ºpop() | bN);
  214.             ┬º┬ºpush(bW);
  215.          }
  216.          ┬º┬ºpush(┬º┬ºfindproperty(bN_E));
  217.          ┬º┬ºpush(bE);
  218.          if(true)
  219.          {
  220.             ┬º┬ºpush(┬º┬ºpop() | bN);
  221.          }
  222.          ┬º┬ºpush(┬º┬ºfindproperty(MAXANGLE));
  223.          ┬º┬ºpush(4294967295);
  224.          if(true)
  225.          {
  226.             ┬º┬ºpush(┬º┬ºpop() + 1);
  227.          }
  228.          ┬º┬ºpush(┬º┬ºfindproperty(CONVRAD));
  229.          ┬º┬ºpush(MAXANGLE);
  230.          if(true)
  231.          {
  232.             ┬º┬ºpush(┬º┬ºpop() / 2 / Math.PI);
  233.          }
  234.       }
  235.       
  236.       private var _Angle:int;
  237.       
  238.       public function CAngle(param1:int = 0)
  239.       {
  240.          if(true)
  241.          {
  242.             super();
  243.             _Angle = param1;
  244.          }
  245.       }
  246.       
  247.       public static function AsCPosition(param1:CPosition) : CAngle
  248.       {
  249.          return new CAngle(Math.atan2(param1.y,param1.x) * CONVRAD);
  250.       }
  251.       
  252.       public static function AsAngle256(param1:Number) : CAngle
  253.       {
  254.          ┬º┬ºpush(CAngle);
  255.          ┬º┬ºpush(param1);
  256.          if(true)
  257.          {
  258.             ┬º┬ºpush(┬º┬ºpop() * (1 << 24));
  259.          }
  260.          return new ┬º┬ºpop()(┬º┬ºpop());
  261.       }
  262.       
  263.       public static function AsXY(param1:Number, param2:Number) : CAngle
  264.       {
  265.          return new CAngle(Math.atan2(param2,param1) * CONVRAD);
  266.       }
  267.       
  268.       public static function AsDirection(param1:int) : CAngle
  269.       {
  270.          return new CAngle(param1 << 29);
  271.       }
  272.       
  273.       public static function DirectionDifference(param1:int, param2:int) : int
  274.       {
  275.          var _loc3_:int = 0;
  276.          if(true)
  277.          {
  278.             ┬º┬ºpush(param2);
  279.             ┬º┬ºpush(param1);
  280.             if(true)
  281.             {
  282.                _loc3_ = ┬º┬ºpop() - ┬º┬ºpop();
  283.                if(true)
  284.                {
  285.                   ┬º┬ºpush(_loc3_);
  286.                   ┬º┬ºpush(3);
  287.                   if(true)
  288.                   {
  289.                      return ┬º┬ºpop() > ┬º┬ºpop() ? _loc3_ - 8 : (_loc3_ < -3 ? _loc3_ + 8 : _loc3_);
  290.                   }
  291.                   ┬º┬ºgoto(addr41);
  292.                }
  293.                ┬º┬ºgoto(addr34);
  294.             }
  295.          }
  296.          ┬º┬ºgoto(addr44);
  297.       }
  298.       
  299.       public function get mAngleDEG() : Number
  300.       {
  301.          return _Angle * CONVDEGM;
  302.       }
  303.       
  304.       public function get mDirectionName() : String
  305.       {
  306.          return mDirectionNames[mDirection];
  307.       }
  308.       
  309.       public function get mDirectionNeighbourID() : String
  310.       {
  311.          return mDirectionNeighbours[mDirection];
  312.       }
  313.       
  314.       public function Add(param1:CAngle) : void
  315.       {
  316.          if(true)
  317.          {
  318.             _Angle += param1._Angle;
  319.          }
  320.       }
  321.       
  322.       public function InvertOrientation() : void
  323.       {
  324.          mAngle += MAXMASK / 2;
  325.       }
  326.       
  327.       public function get mAngle1() : Number
  328.       {
  329.          return mAngle256 / 256;
  330.       }
  331.       
  332.       public function set mAngle(param1:int) : *
  333.       {
  334.          if(true)
  335.          {
  336.             _Angle = param1;
  337.          }
  338.       }
  339.       
  340.       public function get mMatrix() : Matrix
  341.       {
  342.          var _loc1_:Number = NaN;
  343.          var _loc2_:Number = NaN;
  344.          var _loc3_:Number = NaN;
  345.          _loc1_ = mAngleRAD;
  346.          _loc2_ = Math.sin(_loc1_);
  347.          _loc3_ = Math.cos(_loc1_);
  348.          return new Matrix(_loc3_,_loc2_,-_loc2_,_loc3_,0,0);
  349.       }
  350.       
  351.       public function get mDirection() : int
  352.       {
  353.          ┬º┬ºpush(_Angle);
  354.          ┬º┬ºpush(1);
  355.          if(true)
  356.          {
  357.             ┬º┬ºpush(┬º┬ºpop() + (┬º┬ºpop() << 28) >> 29);
  358.             ┬º┬ºpush(7);
  359.          }
  360.          return ┬º┬ºpop() & ┬º┬ºpop();
  361.       }
  362.       
  363.       public function Copy(param1:CAngle) : void
  364.       {
  365.          _Angle = param1._Angle;
  366.       }
  367.       
  368.       public function get mAngleRAD() : Number
  369.       {
  370.          return _Angle * CONVRADM;
  371.       }
  372.       
  373.       public function set mAngleDEG(param1:Number) : *
  374.       {
  375.          if(true)
  376.          {
  377.             ┬º┬ºpush(┬º┬ºfindproperty(_Angle));
  378.             ┬º┬ºpush(param1);
  379.             if(true)
  380.             {
  381.                ┬º┬ºpush(CONVDEG);
  382.                if(true)
  383.                {
  384.                   addr19:
  385.                   ┬º┬ºpush(┬º┬ºpop() * ┬º┬ºpop());
  386.                   ┬º┬ºpush(MAXMASK);
  387.                }
  388.                ┬º┬ºpop()._Angle = ┬º┬ºpop() & ┬º┬ºpop();
  389.                ┬º┬ºgoto(addr22);
  390.             }
  391.             ┬º┬ºgoto(addr19);
  392.          }
  393.          addr22:
  394.       }
  395.       
  396.       public function set mAngle256(param1:Number) : *
  397.       {
  398.          if(true)
  399.          {
  400.             _Angle = param1 << 24;
  401.          }
  402.       }
  403.       
  404.       public function set mDelta(param1:CPosition) : void
  405.       {
  406.          if(true)
  407.          {
  408.             mAngleRAD = param1.mAngleRAD;
  409.          }
  410.       }
  411.       
  412.       public function set mAngleRAD(param1:Number) : *
  413.       {
  414.          _Angle = param1 * CONVRAD & MAXMASK;
  415.       }
  416.       
  417.       public function Equals(param1:CAngle) : Boolean
  418.       {
  419.          return _Angle == param1._Angle;
  420.       }
  421.       
  422.       public function Sub(param1:CAngle) : void
  423.       {
  424.          _Angle -= param1._Angle;
  425.       }
  426.       
  427.       public function GetDelta(param1:Number = 1) : CPosition
  428.       {
  429.          var _loc2_:CPosition = null;
  430.          _loc2_ = mDelta;
  431.          if(param1 != 1)
  432.          {
  433.             _loc2_.normalize(param1);
  434.          }
  435.          return _loc2_;
  436.       }
  437.       
  438.       public function get mDelta() : CPosition
  439.       {
  440.          var _loc1_:* = NaN;
  441.          ┬º┬ºpush(mAngleRAD);
  442.          if(true)
  443.          {
  444.             ┬º┬ºpush(┬º┬ºpop());
  445.          }
  446.          _loc1_ = ┬º┬ºpop();
  447.          return new CPosition(Math.cos(_loc1_),Math.sin(_loc1_));
  448.       }
  449.       
  450.       public function set mDirection(param1:int) : *
  451.       {
  452.          ┬º┬ºpush(┬º┬ºfindproperty(_Angle));
  453.          ┬º┬ºpush(param1);
  454.          if(true)
  455.          {
  456.             ┬º┬ºpush(┬º┬ºpop() << 29);
  457.          }
  458.          ┬º┬ºpop()._Angle = ┬º┬ºpop();
  459.       }
  460.       
  461.       public function get mAngle() : int
  462.       {
  463.          return _Angle;
  464.       }
  465.       
  466.       public function get mAngle256Signed() : Number
  467.       {
  468.          ┬º┬ºpush(_Angle);
  469.          if(true)
  470.          {
  471.             ┬º┬ºpush(1);
  472.             if(true)
  473.             {
  474.                ┬º┬ºpush(┬º┬ºpop() << 23);
  475.             }
  476.             ┬º┬ºpush(┬º┬ºpop() + ┬º┬ºpop() >> 24);
  477.          }
  478.          return ┬º┬ºpop();
  479.       }
  480.       
  481.       public function Scale(param1:Number) : void
  482.       {
  483.          _Angle *= param1;
  484.       }
  485.       
  486.       public function get mAngle256() : Number
  487.       {
  488.          return _Angle + (1 << 23) >> 24 & 255;
  489.       }
  490.       
  491.       public function get mDirectionObject() : Object
  492.       {
  493.          return mDirectionByIndex[mDirection];
  494.       }
  495.       
  496.       public function TurnAngle(param1:CAngle) : CAngle
  497.       {
  498.          return new CAngle(param1._Angle - _Angle);
  499.       }
  500.       
  501.       public function set mDirectionName(param1:String) : *
  502.       {
  503.          mDirection = mDirectionNames.indexOf(param1);
  504.       }
  505.       
  506.       public function GetTurnCount(param1:CAngle) : int
  507.       {
  508.          var _loc2_:int = 0;
  509.          if(true)
  510.          {
  511.             _loc2_ = mAngle / param1.mAngle;
  512.             return _loc2_ >= 0 ? _loc2_ : int(-_loc2_);
  513.          }
  514.          ┬º┬ºgoto(addr29);
  515.       }
  516.       
  517.       public function Clone() : CAngle
  518.       {
  519.          return new CAngle(_Angle);
  520.       }
  521.    }
  522. }
  523.